Core.Test.registerTest({
	group: "dao",
	name: "Core.Storage.DaoProxy",
	envs: ["storage.simple"],
	
	_should: {
		error: {
			"Should error on setting into any other variable type": "Can't perform setting on non-dao property.",
			"Should error on setting using path without leading dots": "Path 'user.login.name' does not have any leading dots."
		}
	},
	
	before: function() {
		this.conf = new Core.Storage.Configuration();
		this.valuer = new Core.Storage.DaoProxy(this, this.conf, null);
		
		this.daoA = this.valuer.createDao("..user.current");
		this.daoB = this.valuer.createDao("..user.login");

	},
	
	override: function(property, value) {
		this.conf.override(property, value, this, 20);
	},
	
	"Should get using global path": function() {
		Assert.equal("Bilbo", this.valuer.get("..user.login.name"));
	},
	
	"Should get primitive using local path": function() {
		this.override("prop", 10);
		Assert.equal(10, this.valuer.get(".prop"));
	},
	
	"Should get & evaluate dao expression using local path": function() {
		this.override("prop", this.daoA);
		Assert.equal({site: 2}, this.valuer.get(".prop"));
	},
	
	"Should get & evaluate dao expression using local path with tail": function() {
		this.override("prop", this.daoA);
		Assert.equal(2, this.valuer.get(".prop.site"));
	},
	
	"Should set using global path": function() {
		this.valuer.set("..user.login.name", "Frodo");
		Assert.equal("Frodo", Core.Storage.get("user.login.name"));
	},
	
	"Should set dao expression using local path": function() {
		this.override("login", this.daoB);
		this.valuer.set(".login", {surname: "Fafa"});
		
		Assert.equal({surname: "Fafa"}, this.valuer.get(".login"));
		Assert.equal({surname: "Fafa"}, Core.Storage.get("user.login"));
	},
	
	"Should set dao expression using local path with tail": function() {
		this.override("login", this.daoB);
		this.valuer.set(".login.name", "Frodo");
		
		Assert.equal("Frodo", this.valuer.get(".login.name"));
		Assert.equal("Frodo", Core.Storage.get("user.login.name"));
	},
	
	"Should error on setting into any other variable type": function() {
		this.override("prop", ["a", "aa" ,"aaa"]);
		this.valuer.set(".prop.1", "bb");
	},
	
	"Should error on setting using path without leading dots": function() {
		this.valuer.set("user.login.name", "Frodo");
	}
});